// 消息管理接口文档
import { api } from 'boot/axios'

/**参数：
 * title	String	消息标题
 * content	String	消息内容
 * type	Integer	消息类型（1:通知, 2:公告, 3:私信）
 **/
export interface IMessageParam {
  title: string
  content: string
  type: number
}
export interface IEditMessageParam extends IMessageParam {
  id: number
}

const MESSAGE_URL = '/house/message'
const MESSAGE_LIST_URL = '/house/message/list'

// Message
export function addMessage(data: IMessageParam) {
  return api.post(MESSAGE_URL, data)
}
export function editMessage(data: IEditMessageParam) {
  return api.put(MESSAGE_URL, data)
}
export function removeMessage(id: number) {
  return api.delete(`${MESSAGE_URL}/${id}`)
}
export function getMessageById(id: number) {
  return api.get(`${MESSAGE_URL}/${id}`)
}

interface IMessageListParam {
  pageNum: number
  pageSize: number
  type?: number | undefined
}
export function getMessagePageList(
  type: number | undefined = undefined,
  pageNum: number = 1,
  pageSize: number = 2
) {
  const params: IMessageListParam = { pageNum, pageSize }
  if (type !== undefined) {
    params.type = type
  }
  return api.get(MESSAGE_LIST_URL, { params })
}
